
<template>
    <div>
        <mt-header title="新增代理">
            <router-link to="/" slot="left">
                <i class="mintui mintui-back lic-d"></i>
            </router-link>
        </mt-header>
        <div class="search">
            <h5>新增代理后，此代理自动成为下级代理。</h5>
            <input type="text" class="bd" placeholder="输入代理ID" v-model="agentId">
            <input type="text" class="bd" placeholder="输入代理名称" v-model="agentName">
            <input type="text" class="bd" placeholder="输入房卡数" v-model="gems">
            <input type="text" class="bd" placeholder="输入手机号" v-model="telephone">
            <input type="password" class="bd" placeholder="输入密码" v-model="kpassword">
            <button class="btn" @touchend='postaddagent'>确定</button>
        </div>
    </div>
</template>



<script>
    import {
        addagent
    } from '../api/api'
    import {
        Toast
    } from 'mint-ui';
    export default {
        data() {
            return {
                agentId: '',
                agentName: '',
                kpassword: '',
                gems: '',
                telephone: '',
                wechat: '',
                alipay: ''
            }
        },
        methods: {
            postaddagent() {
                let admin = {
                    agentId: this.agentId,
                    agentName: this.agentName,
                    kpassword: this.kpassword,
                    telephone: this.telephone,
                    gems: this.gems,
                }
                let reg = /^((13|14|15|17|18)[0-9]{1}\d{8})$/; //手机号正则
                let sz = /^[0-9]*$/ //数字正则
                if (this.telephone == '') {
                    alert('手机号码不能为空')
                    return
                } else if (!reg.test(this.telephone)) {
                    alert('手机号码格式不正确')
                    retur
                } else if (this.gems == '') {
                    alert('房卡不能为空')
                    return
                } else if (!sz.test(this.gems)) {
                    alert('房卡格式为数字')
                    return
                }

                addagent(admin).then(res => {
                    console.log(res)
                    if(res.data.code == "0"){
                        this.agentId='',
                        this.agentName='',
                        this.kpassword='',
                        this.telephone='',
                        this.gems=''
                        Toast('新增成功');
                    }else if(res.data.code == 1){
                        
                        Toast(res.data.message);
                    
                    }
                })
                
            }
        }
    }
</script>



<style scoped lang="less">
    a {
        text-decoration: none;
    }
    .lic-d {
        font-size: 50px;
    }
    .mint-header {
        background: -webkit-linear-gradient(left, #6180F4, #79CBFA);
        font-size: 36px;
        height: 80px;
    }
    .search {
        width: 100%;
        box-sizing: border-box;
        padding: 12px 54px;
        input {
            width: 100%;
            height: 100%;
            outline: 0;
            border: 0;
        }
        h5 {
            margin: 0;
            padding: 0;
            font-size: 32px;
            margin-bottom: 20px;
            font-weight: normal;
            color: rgb(110, 108, 108);
        }
        .bd {
            border: 2px solid #cccccc;
            border-radius: 10px;
            height: 80px;
            margin-bottom: 20px;
            font-size: 28px;
            padding: 0;
        }
    }
    .btn {
        width: 100%;
        height: 80px;
        display: block;
        background-color: #74B2F8;
        outline: 0;
        border: 0;
        border-radius: 10px;
        margin: 0 auto;
        font-size: 40px;
    }
    .bd::-webkit-input-placeholder {
        color: #aab2bd;
        font-size: 28px;
        padding-left: 10px;
    }
</style>